package com.shop.loan.model.view;

import com.shop.loan.model.Channel;
import com.shop.loan.proxy.StatisticsByRepaymentDayProxy;
import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.Readonly;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.annotation.sub_field.sub_edit.VL;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import java.math.BigDecimal;
import java.util.Date;

@Setter
@Getter
@Entity
@Table(name = "s_statistics_day",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = {"day", "type"})
        })
@Erupt(
        name = "每日还款统计",
        orderBy = "id desc",
        dataProxy = StatisticsByRepaymentDayProxy.class,
        power = @Power(add = false, edit = false, viewDetails = false, delete = false, export = true)
)
public class StatisticsByRepaymentDay extends BaseModel {

    @EruptField(
            views = @View(title = "日期"),
            edit = @Edit(title = "日期",
                    readonly = @Readonly,
                    search = @Search(),
                    dateType = @DateType(type = DateType.Type.DATE))
    )
    private Date day;


    @EruptField(
            views = @View(title = "新老客户", width = "80px"),
            edit = @Edit(
                    title = "新老客户",
                    type = EditType.CHOICE,
                    search = @Search(),
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "全部", value = "1"),
                                    @VL(label = "新客户", value = "2"),
                                    @VL(label = "老客户", value = "3"),
                            }
                    ))
    )
    private Integer type;


    @Transient
    @EruptField(
            edit = @Edit(
                    title = "所属渠道",
                    search = @Search(vague = true),
                    type = EditType.REFERENCE_TREE
            )
    )
    private Channel channel;


    @Transient
    @EruptField(
            views = @View(title = "应还订单数", width = "80px")
    )
    private Integer orderNumByTotal;


    @Transient
    @EruptField(
            views = @View(title = "部分还款订单数", width = "100px")
    )
    private Integer orderNumByPart;


    @Transient
    @EruptField(
            views = @View(title = "结清还款订单数", width = "100px")
    )
    private Integer orderNumBySettle;


    @Transient
    @EruptField(
            views = @View(title = "账单回款率(%)", width = "100px", desc = "结清订单数/总订单数")
    )
    private BigDecimal orderNumRateByRepay;


    @Transient
    @EruptField(
            views = @View(title = "应还账单金额")
    )
    private BigDecimal totalMoney;


    @Transient
    @EruptField(
            views = @View(title = "应还账单本金")
    )
    private BigDecimal principalByTotal;

    @Transient
    @EruptField(
            views = @View(title = "总还款金额")
    )
    private BigDecimal repayMoneyByTotal;


    @Transient
    @EruptField(
            views = @View(title = "部分还款金额")
    )
    private BigDecimal repayMoneyByPart;


    @Transient
    @EruptField(
            views = @View(title = "结清还款金额")
    )
    private BigDecimal repayMoneyBySettle;


    @Transient
    @EruptField(
            views = @View(title = "金额回款率(%)")
    )
    private BigDecimal repayRate;


    @Transient
    @EruptField(
            views = @View(title = "利润",width = "80px")
    )
    private BigDecimal profit;


    @Transient
    @EruptField(
            views = @View(title = "本金回款率(%)")
    )
    private BigDecimal principalRate;


    @Transient
    @EruptField(
            views = @View(title = "今日逾期订单数")
    )
    private Integer orderNumByOverdue;


    @Transient
    @EruptField(
            views = @View(title = "今日逾期金额")
    )
    private BigDecimal overdueMoney;


    @Transient
    @EruptField(
            views = @View(title = "逾期率(%)")
    )
    private BigDecimal overdueRate;

}
